import axios from 'axios'

const request = axios.create({
	timeout: 5000,
	timeoutErrorMessage: '请求超时'
})

request.interceptors.request.use(config => {
	config.headers!.token = 'XXXXXXXXXXXXXXXXXX'
	return config
}, error => {
	return Promise.reject(error)
})




request.interceptors.response.use(response => {
	const { code } = response.data
	switch (code) {
		case 400:
			console.log('非法权限')
			break
		case 401:
			console.log('token 非法')
			break
		case 403:
			console.log('权限不够')
			break
		case 404:
			console.log('资源不存在')
			break
	}
	return response
}, error => {
	return Promise.reject(error)
})



export default request